
/* Generated by Interface Builder */

#import "MenuView.h"
#import <dpsclient/wraps.h>
#import <appkit/color.h>
#import "MenuItems.h"


@implementation MenuView : View


- initFrame: (NXRect *) frameRect;
{
    [super initFrame:frameRect];
    
    return self;
}


- drawVerticalMenu
{
    int i;
    float y;
    float x_center;
    float item_height, item_width, item_distance;
    NXRect rect;
    
    /* converts item millimeters to PS coord values */
    item_width = MM_CONVERT * option1;
    item_height  = MM_CONVERT * option2;
    item_distance = MM_CONVERT * option3;

    [self getFrame:&rect];   /* get view size */
    x_center = (rect.size.width / 2.0) - (item_width / 2.0);
    
    y = rect.size.height/2.0 + (numItems *(item_distance+item_height)) / 2.0;
    
    for ( i = 0; i < numItems; i++, y -= (item_distance+item_height) )
    {
        if ( hitItem == i )
	    NXSetColor(selectedColour);
	else
	    NXSetColor(unselectedColour);
	    
	menu_rect(x_center, y, item_height, item_width);
        PSgsave(); PSfill(); PSgrestore();
        PSsetgray(0.0);
        PSstroke();
    }
    
    return self;
}

- drawCirclePieMenu
{
    int i;
    float x_center, y_center;
    NXRect rect;
    float angle = 360 / (float) numItems;

    [self getFrame:&rect];   /* get view size */
    x_center = rect.size.width / 2.0;
    y_center = rect.size.height / 2.0;
    
    for ( i = 0, angle = 0.0; i < numItems;
          i++, angle += 360/(float) numItems )
    {
        if ( hitItem == i )
	    NXSetColor(selectedColour);
	else
	    NXSetColor(unselectedColour);

        menu_pie(x_center, y_center, angle, angle+option1,
	         MM_CONVERT * option2, MM_CONVERT * (option2+option3));
	PSgsave(); PSfill(); PSgrestore();
	PSsetgray(0.0);
	PSstroke();
    }
    
    return self;
}


- drawCircleRectMenu
{
    int i;
    NXRect rect;
    float x_center, y_center;
    float angle = 360 / (float) numItems;

    [self getFrame:&rect];   /* get view size */
    x_center = rect.size.width / 2.0 - (MM_CONVERT * option1);
    y_center = rect.size.height / 2.0;
    
    for ( i = 0, angle = 0.0; i < numItems;
          i++, angle += 360/(float) numItems )
    {
        if ( hitItem == i )
	    NXSetColor(selectedColour);
	else
	    NXSetColor(unselectedColour);
	    
        menu_pie_rect(x_center, y_center, MM_CONVERT * option3, angle,
	              MM_CONVERT * option1, MM_CONVERT * option2);
        PSgsave(); PSfill(); PSgrestore();
        PSsetgray(0.0);
        PSstroke();
    }    
    
    return self;
}


- drawSelf: (NXRect *) drawRects : (int) rectCount
{
    NXEraseRect(&bounds);

    if ( menuType == VERTICAL )
        [self drawVerticalMenu];
    else if ( menuType == CIRCLE_PIE )
        [self drawCirclePieMenu];
    else
        [self drawCircleRectMenu];

    return self;
}



- setMenuParms:(MVParms *) parms
{
    numItems = parms->num_items;
    menuType = parms->menu_type;
    option1  = parms->option1;
    option2  = parms->option2;
    option3  = parms->option3;
    unselectedColour = parms->unselected_colour;
    selectedColour   = parms->selected_colour;

    [self display];
        
    return self;
}

- setHitItem:(int) hit_item
{
    hitItem = hit_item;
    
    return self;
}

@end
